import time
from operator import index

import pytest
from selenium.webdriver.common.by import By
from config.config import SMP_URL_DEVICE_MODEL
from page.page_index import index
from common.logger import logger


class Test:
    def setup_class(self):  # 先登录，再去业务规则页面
        logger.info("*** 管理界面——业务规则初始化 ***")
        self.index = index
        self.rule = index.index_service_rule()
        self.index.index_login().login("byhy", "sdfsdf")
        self.rule.goto_service_rule_page()

    def teardown_class(self):
        logger.info("*** 管理界面——业务规则结束 ***")
        self.close = self.index.close()

    @pytest.fixture(scope="function")
    def delServiceRule(self):
        yield
        # 清除表单第一项内容
        self.rule.rule_del_frist_item()
        # 刷新页面，为下一条用例进行下一次输入
        self.index.driver.refresh()

    @pytest.mark.parametrize("name, ruleType, minFee, exceptFee, desc, freeRate", [
        ("全国-电瓶车充电费率1", "预付费-下发业务量", "0.1", "2", "电瓶车充电率", ["千瓦时", "1"]),
        ("南京-洗车机费率1", "预付费-下发费用", "2", "10", "洗车机费率", ""),
        ("南京-存储柜费率1", "后付费-上报业务量", "", "", "存储柜费率",
         [["100L", "小时", "2"], ["50L", "小时", "1"], ["10L", "小时", "0.5"]])
    ])
    def test_SMP_service_rule_001(self, delServiceRule, name, ruleType, minFee, exceptFee, desc, freeRate):
        logger.info(f"***添加——业务规则***  规则类型：{ruleType}")
        # 通过链式访问 获取结果
        ruleName = self.rule.add_service_rule(name, ruleType, minFee, exceptFee, desc, freeRate).get_text()
        assert ruleName == name
